Vue.component("end-com", {
    template: `<div class="end-com">
                    <span>答题结果如下：</span>
                    <div :class="style = item.keyVal===item.key?'true':'error'" v-for="item,index in list">id：{{item.id}}-------{{item.keyVal===item.key?"√":"×"}}-----分值：{{item.grade}}</div>
                    <div class="sum">总分：{{sum}}</div>
                </div>`,
    data() {
        return {
            list: [],
            style: ""
        }
    },
    computed: {
        sum() {
            var _sum = 0
            this.list.forEach(val => {
                if (val.keyVal === val.key) {
                    _sum += val.grade
                }
            }); 
            return _sum;
        }
    },
    mounted() {
        var _this = this
        bus.$on("showResult", (list) => {
            _this.list = list
        })
    }
})

